home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 July & August / PCWorld_2007-07-08_cd.bin / komunikace / ie7pro / IE7proSetup.exe / {app} / plugins / accuweather / js / findLocation.js
Text File  |  2007-03-20  |  3KB  |  93 lines

  1. //initialize the findLocation window
  2. function init() {
  3.     var currentSetting=PRO_getValue("weather_Location","");
  4.     if (currentSetting!="") {
  5.       PRO_log(currentSetting)
  6.       arr = currentSetting.split("|");
  7.       if(arr[3])
  8.           envVar.innerText=arr[3];
  9.         else
  10.           envVar.innerText=currentSetting;
  11.     }
  12.     var currentUnit=PRO_getValue("weather_Unit","");
  13.     if (currentUnit!="english") {
  14.       metric.checked = true;    
  15.     }else{
  16.     english.checked = true;    
  17.   }
  18.  
  19. }
  20. //load the xml data from the website
  21. function loadData() {
  22.     req = PRO_xmlhttpRequest();
  23.     if (req) {
  24.         req.open("GET","http://vwidget.accuweather.com/widget/vista1/locate_city.asp?location=" + envVar.value,true);
  25.         req.onreadystatechange=processData;
  26.         req.send();
  27.     }
  28. }
  29.  
  30. //process data when its received
  31. function processData() {
  32.     if (req.readyState==4) {
  33.         if (req.status==200) {
  34.             parseData(req.responseXML.documentElement);
  35.         }
  36.     }
  37. }
  38.  
  39. //parse the xml data and populate the table with data.
  40. function parseData(xmlData) {
  41.     tempNode=xmlData.getElementsByTagName("./citylist").item(0);
  42.     tempNodes=tempNode.getElementsByTagName('location');
  43.     deleteRows("LocationTable");
  44.     for (count=0;count<tempNodes.length;count++) {
  45.         cityNode=tempNodes[count];
  46.         tempString="<a class=\"link\" href=\"#\" onClick=\"selectLocation('" + cityNode.getAttribute("location") + "');return false;\">+</a>  ";
  47.         tempString1="<a class=\"link\" href=\"#\" onClick=\"selectLocation('" + cityNode.getAttribute("location") + "');return false;\">" + cityNode.getAttribute("city") + ", " + cityNode.getAttribute("state") + "</a>";
  48.         addRow("LocationTable",tempString,tempString1);
  49.     }
  50.     if (tempNodes.length==0) {
  51.         addRow("LocationTable","Location not found","");
  52.     }
  53.     with (scrollTableContainer.style) {
  54.         display="block";
  55.     }
  56. }
  57.  
  58. //add a row programatically to a table
  59. function addRow(id,value,text){
  60.     var tbody=document.getElementById(id).getElementsByTagName("tbody")[0];
  61.     var row=document.createElement("TR");
  62.     var cell1=document.createElement("TD");
  63.     cell1.innerHTML=value;
  64.     cell1.style.whiteSpace="nowrap";
  65.     var cell2=document.createElement("TD");
  66.     cell2.innerHTML=text;
  67.     cell2.style.whiteSpace="nowrap";
  68.     row.appendChild(cell1);
  69.     row.appendChild(cell2);
  70.     tbody.appendChild(row);
  71. }
  72.  
  73. //delete a row from a table
  74. function deleteRows(id) {  
  75.     var tbl=document.getElementById(id);
  76.     totalRows=tbl.rows.length;
  77.     for (count=0;count<totalRows;count++) {
  78.         document.getElementById(id).deleteRow(0);
  79.     }
  80. }
  81.  
  82. //if a location is selected save it to the settings and close the flyout
  83. function selectLocation(locationCode) {
  84.     PRO_setValue("weather_Location",locationCode);
  85.     alert("Location Selected. \rNow We will close config window.");
  86.     window.close();
  87. }
  88. function selectUnit(Unit) {
  89.     PRO_setValue("weather_Unit",Unit);
  90.     PRO_log("set weather_Unit " + Unit)
  91.     //alert("Unit Selected. ");
  92. }
  93.